package com.heatingcharge.controller.sys;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heatingcharge.common.util.R;
import com.heatingcharge.dto.SysRoleDTO;
import com.heatingcharge.entity.sys.SysRole;
import com.heatingcharge.param.SysRoleParam;
import com.heatingcharge.service.sys.ISysRoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 角色  前端控制器
 * </p>
 *
 * @author devin.jiang
 * @since 2019-06-26
 */
@RestController
@RequestMapping("/sys-role")
public class SysRoleController {
    @Autowired
    ISysRoleService sysRoleService;

    @GetMapping("/list")
    public R getRoleList(SysRole sysRole){
        return R.ok(sysRoleService.getRoleList(sysRole));
    }

    @GetMapping
    public R getSysRoles(Page page, SysRoleDTO sysRoleDTO){
        IPage<SysRole> sysRoleDTOIPage=sysRoleService.getSysRoles(page,sysRoleDTO);
        return R.ok(sysRoleDTOIPage);
    }

    @PostMapping
    public R saveSysRole(@RequestBody SysRoleParam sysRoleParam){
        if (sysRoleService.save(sysRoleParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "更新角色",notes = "更新角色")
    @PutMapping
    public R updateSysRole(@RequestBody SysRoleParam sysRoleParam){
        if (sysRoleService.update(sysRoleParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "删除角色",notes = "根据主键ID删除角色")
    @DeleteMapping("/{id}")
    public R delSysRole(@PathVariable("id") Integer id){
        if (sysRoleService.removeById(id)){
            return R.ok();
        }
        return R.error();
    }
}

